package com.letoy.edu.service.Impl;

import com.letoy.edu.dao.ScoreInfoMapper;
import com.letoy.edu.entity.ScoreInfo;
import com.letoy.edu.service.ScoreInfoService;
import com.letoy.edu.vo.Score;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class ScoreInfoServiceImpl implements ScoreInfoService {

    @Autowired
    ScoreInfoMapper scoreInfoMapper;

    @Override
    public HashMap<String, Object> insertScoreInfo(ScoreInfo scoreInfo) {
        HashMap<String, Object> hashMap = new HashMap<>();
        int result = scoreInfoMapper.insertScoreInfo(scoreInfo);
        if (result == 0) {
            hashMap.put("status", "1");
            hashMap.put("msg", "新增失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("msg", "新增成功");
        return hashMap;

    }

    @Override
    public HashMap<String, Object> deleteScoreInfo(int scoreId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        int result = scoreInfoMapper.deleteScoreInfo(scoreId);
        if (result == 0) {
            hashMap.put("status", "1");
            hashMap.put("msg", "删除失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("msg", "删除成功");
        return hashMap;
    }

    @Override
    public HashMap<String, Object> updateScoreInfo(ScoreInfo scoreInfo) {
        HashMap<String, Object> hashMap = new HashMap<>();
        int result = scoreInfoMapper.updateScoreInfo(scoreInfo);
        if (result == 0) {
            hashMap.put("status", "1");
            hashMap.put("msg", "更新失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("msg", "更新成功");
        return hashMap;
    }

    @Override
    public HashMap<String, Object> getScoreInfoByScoreId(int scoreId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        Score scoreInfoByScoreId = scoreInfoMapper.getScoreInfoByScoreId(scoreId);
        if (scoreInfoByScoreId == null) {
            hashMap.put("status", "1");
            hashMap.put("msg", "查询失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("data", scoreInfoByScoreId);
        hashMap.put("msg", "查询成功");
        return hashMap;
    }

    @Override
    public HashMap<String, Object> getAllScoreInfo() {
        HashMap<String, Object> hashMap = new HashMap<>();
        List<ScoreInfo> allScoreInfo = scoreInfoMapper.getAllScoreInfo();
        if (allScoreInfo.isEmpty()) {
            hashMap.put("status", "1");
            hashMap.put("msg", "查询失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("data", allScoreInfo);
        hashMap.put("msg", "查询成功");
        return hashMap;
    }
}
